package com.hhxy.utils;

import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Stream;

/**
 * @auther:Lu Yao
 * @date:2022/3/31
 * @description:
 **/
public class MySearchPlan {
   private String text;
   private String pattern;


    public MySearchPlan(String text,String pattern){
        this.text=text;
        this.pattern=pattern;
    }

    public String getCharacter(){
         /*String[] goodCharacter=new String[Character.MAX_VALUE+1];
         String[] badCharacter=new String[Character.MAX_VALUE+1];*/
         //起始位置
        int nowPosition=0;
        //落地位置
        int lastPosition=pattern.length();
        //移动位数
        int moveStep=0;
        //所要搜索关键文字的长度
        int pLength=pattern.length();
        //全部文本最大索引位置
        int tMaxPosition=text.length()-1;
        //pattern命中次数
        int time=0;
        //如果text起始位置到最大文本位置长度大于pattern的长度，则循环继续
        while ((tMaxPosition-nowPosition)>=pLength){

            String substring = text.substring(nowPosition, lastPosition);
            //这里不是moore的思想，仍是从左到右逐个字符进行匹配
            if (substring.equals(pattern)){
                time++;
                System.out.printf("当前命中%d次\n",time);
            }
            nowPosition++;
            lastPosition++;
            //计算根据moore思想计算移动的位置数，用移动位置数来代替自增
            for (int i = (substring.length()-1); i >=0 ; i--) {
                char subChar = substring.charAt(i);
                char patternChar = pattern.charAt(i);
                if (subChar!=patternChar){
                    //判断是否包含该字符
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {

     /*   Scanner cin=new Scanner(System.in);
        String str=cin.nextLine();
        String pattern=cin.nextLine();
        MySearchPlan mySearchPlan = new MySearchPlan(str, pattern);
        long start = System.currentTimeMillis();
        mySearchPlan.getCharacter();
        long end = System.currentTimeMillis();
        System.out.printf("总共用时%d毫秒",(end-start));
        SecureRandom secureRandom = new SecureRandom();
        System.out.println(secureRandom.nextInt());
        Random random=new Random();
        System.out.println(random.nextInt());
        */
      /*  Stream<String> stream = Arrays.stream(new String[]{"1", "2", "3"});
        stream.forEach(System.out::println);
        try {
            String a="2022-12-02";
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = simpleDateFormat.parse(a);
            boolean before = parse.before(new Date());
            System.out.println(before);
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
   /*   String a=">><&'afaf\"asdfa";
        Scanner scanner = new Scanner(System.in);
        a = scanner.next();
        a=a.replaceAll("&","&amp;").replaceAll(">", "&gt;").replace("<", "&lt;").replaceAll("'", "@apos;")
              .replaceAll("\"", "&quot;");
        System.out.println(a);*/

        /*try {
            isTimeRange();
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
        System.out.print("\033[32;2;3m"+"文字");
    }




        /**
         * 判断日期是否在指定范围
         * @return
         * @throws ParseException
         */
        public static boolean isTimeRange() throws ParseException {
           // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date time = new Date();
            SimpleDateFormat df = new SimpleDateFormat("HH:mm");
            Date now = df.parse(df.format(time));
            Date begin = df.parse("8:00");
            Date end = df.parse("18:00");
            Calendar nowTime = Calendar.getInstance();
            nowTime.setTime(now);
            Calendar beginTime = Calendar.getInstance();
            beginTime.setTime(begin);
            Calendar endTime = Calendar.getInstance();
            endTime.setTime(end);
            if (nowTime.before(endTime) && nowTime.after(beginTime)) {
                System.out.println(end+""+begin+""+now);
                System.out.println(endTime+""+beginTime+""+nowTime);
                return true;
            } else {
                return false;
            }
        }

}